home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: C++ Questions.
- Date: 24 Feb 1996 11:40:00 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4gmteg$fed@news1.usa.pipeline.com>
- NNTP-Posting-Host: pipe4.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Feb 21, 1996 18:30:45 in article <C++ Questions.>,
- 'afalgout@ocean.st.usm.edu (Andrew Wilson Falgout)' wrote:
-
-
- >Ok here it goes. I know I'll probably receive a few flames from showing
- >my lack of knowledge but I need answers.
-
- Sorry, I'm out of matches, so no flames...
-
- >1> What is the Heap exactly? Is it similar to a stack? Or is it just
- >another word for a pool of memory.
-
- Roughly, it's a memory pool. Definitely not the stack.
-
- >2> What is the difference between a virtual function and a normal
- function.
-
- A virtual function is one that contains one or more definitions
- from which the appropriate one is selected at run time. A normal
- function, on the other hand, is known at compile time. A normal
- function is more efficient, although by a very small margin, but
- a virtual function can be more flexible depending on circumstances.
- To really understand virtual functions, you need to be aware of the
- concept of polymorphism as well as other OO topics. A very small
- contrived example illustrates the basics:
-
- Suppose you have objects that are containers for liquids and
- gases, you have defined both to be a kind of a container (in
- C++ lingo Container is a base class) and you have a Fill function
- defined for each object. To fill a liquid container, the function
- moves it under a faucet, turns on the faucet and shuts it off
- when the liquid level reaches the top. To fill a gas container,
- you connect it to a gas pipe, turn the valve on, and turn it
- off when the pressure reaches some predetermined level.
-
- Notice that the concept of Fill is the same even though the
- details are different. If you are writing an assembly line
- routine, without OO, you'd have to have two versions
- of:
- get a container
- call its fill function
- label it
- check it
- move it to its destination
-
- With OO, you can write a single procedure that captures
- the assembly line process without needing to know whether
- you're dealing with cans or tanks. Just call a function
- that performs the above steps on a basic container object.
- The virtual mechanism "knows" which kind of a container
- is currently being processed and automatically selects the
- correct Get(), Fill(), Label(), Check(), and Dispose().
-
- Without OO, you'd have to code a test procedure something
- like:
- switch (container_type)
- {
- case BOTTLE:
- FillBottle(); break;
- case CAN:
- FillCan() ....
-
-
-
- >3> What is the purpose of precompiler directives? An example would
- >probably help me understand this one better.
-
- Precompiler directives? Maybe you mean preprocessor directives.
- They are "interpreted" or "evaluated" before the compiler is invoked.
- Typical uses are to define constants and include header files.
-
- #include "header.h" causes the system to insert the text in file
- header.h in the source code at the place where the #include
- directive is located.
-
- #define FOO 5
- causes the preprocessor to substitute the number 5 everywhere
- in your code where you have written FOO. This way, if you
- need to change the value of FOO, you only have to change
- it in one place and recompile. This, BTW, is C style and is
- not widely used by C++ programmers as constant variables
- serve a similar function and provide some advantages in
- debugging as well as type-safety.
-
- >4> Is there an easy way to explain Overloading things? Like Overloading
- >an Operator.
- >5> What is run-time?
- >6> How many different type/kinds of classes are there. And what's the
- >difference between them?
- >There are many more questions that come to mind but I really don't
- >wish to take up anymore of everyone's time right now. Thank you for
- >whatever help I get. And please don't flame a person who wants to learn.
- >
-
- Running out of time. Your questions indicate that you really should
- consult a text book if you want to know.
- --
- Pete Grant
- Kalevi, Inc.
- Software Engineering & development
-